from selenium.webdriver.support.wait import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class BasePage:
    def __init__(self, driver,timeout = 10):
        self.driver = driver
        self.wait = WebDriverWait(self.driver,timeout)

    def open(self,url):
        """打开指定的网页"""
        self.driver.get(url)

    def find(self,locator):
        """找到元素（只保证出现在DOM中）"""
        return self.wait.until(EC.presence_of_element_located(locator))

    def click(self,locator):
        """等待元素可点击并点击"""
        self.wait.until(EC.element_to_be_clickable(locator)).click()

    def type(self,locator,text):
        """清空输入框的内容，并传入text内容"""
        e1 = self.find(locator)
        e1.clear()
        e1.send_keys(text)

    def visibility_text(self,locator):
        """返回可见元素文本"""
        return self.wait.until(EC.visibility_of_element_located(locator)).text
